<?


Class NIVGameModule{
    var $_connect;
    var $error;
    function NIVGameModule() {
        $this->_connect = new Dataconnection();
    }
    function getcountByCountry($country){
        $country=  str_replace(" ", "", $country);
        $SQLCommand="
        SELECT 
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null 
                AND `country`='$country') as total,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Game online%'
                AND `country`='$country') as gameonline,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Mobile Game%'
                AND `country`='$country') as mobilegame,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Web Game%'
                AND `country`='$country') as webgame,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Social Game%'
                AND `country`='$country') as socialgame
        
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    function getcount(){
        $SQLCommand="
        SELECT 
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null 
                ) as total,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Game online%'
                ) as gameonline,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Mobile Game%'
                ) as mobilegame,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Web Game%'
                ) as webgame,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null AND `type` LIKE '%Social Game%'
                ) as socialgame,
            (SELECT count(*) FROM `game`  
                WHERE `delete` is null 
                AND `type` NOT LIKE '%Game online%'
                AND `type` NOT LIKE '%Mobile Game%'
                AND `type` NOT LIKE '%Web Game%'
                AND `type` NOT LIKE '%Social Game%'
                ) as other
        
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    function getGameAll($type,$groupby="''"){
        switch ($type){
            case "Online":
                $type="Game Online";
                break;
            case "Web":
                $type="Web Game";
                break;
            case "Social":
                $type="Social Game";
                break;
            case "Mobile":
                $type="Mobile Game";
                break;
        }
        if($type=="Other"){
            $SQLCommand="
            SELECT *,$groupby as `group`
            FROM `game` 
            WHERE `delete` is null 
                AND `type` NOT LIKE '%Game online%'
                AND `type` NOT LIKE '%Mobile Game%'
                AND `type` NOT LIKE '%Web Game%'
                AND `type` NOT LIKE '%Social Game%'
            ORDER BY `group` ASC
            ";
        }else{
            $SQLCommand="
            SELECT *,$groupby as `group`
            FROM `game` 
            WHERE `delete` is null ".(isset($type)?"AND `type` LIKE '%$type%'":"")."
            ORDER BY `group` ASC
            ";
        }
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function getGameByCountry($country,$groupby="''"){
        $country=  str_replace(" ", "", $country);
        $SQLCommand="
        SELECT *,$groupby as `group`
        FROM `game` 
        WHERE `delete` is null AND `country`='$country'
        ORDER BY `group` ASC
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    
}
?>